package club.babyf.nativeai.demo.algorithm;

import java.util.HashMap;
import java.util.Map;

/**
 * _24_FindTwoSumNotOrder.
 *
 * @author zhanglei.
 * @date 2025/7/26 08:32.
 * @description 无序数组的两数之和.
 */
public class _24_FindTwoSumNotOrder {

    public static int[] findTwoSumNotOrder(int[] arr, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < arr.length; i++) {
            int res = target - arr[i];
            if (map.containsKey(res)) {
                return new int[] {map.get(res), i};
            }
            map.put(arr[i], i);
        }
        return new int[] {};
    }

    private static void print(int[] arr) {
        for (int i : arr) {
            System.out.print(i + " | ");
        }
        System.out.println();
    }

    public static void main(String[] args) {
        int[] arr = {9, 7, 5, 3, 1};
        int[] twoSumOrder = findTwoSumNotOrder(arr, 10);
        print(twoSumOrder);
    }

}
